package com.ihcy.base.controller;

import com.ihcy.base.core.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@RestController
@RequestMapping("test")
public class TestController {

    private static final AtomicInteger count = new AtomicInteger(0);

    @GetMapping("processRequest")
    public Result<Void> processRequest(HttpServletRequest request) throws InterruptedException {
        int i = count.incrementAndGet();
        log.info("ip:{},线程:{},time:{},数量:{}",
                request.getRemoteAddr(),
                Thread.currentThread().getName(),
                System.currentTimeMillis(),
                i);
        // 休眠0.5 秒,导致部分请求一次性处理不了而进入等待队列
        Thread.sleep(500);
        return Result.ok(null);
    }
}
